//
//  ZClubCell.m
//  WeClubs
//
//  Created by Zed Link on 7/4/2017.
//  Copyright © 2017 Zed. All rights reserved.
//

#import "ZClubCell.h"
#import "UIView+ZUtilities.h"
#import <SDWebImage/UIImageView+WebCache.h>

@interface ZClubCell ()

@property (weak, nonatomic) IBOutlet UIImageView *logoImgView;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UIButton *memberBtn;
@property (weak, nonatomic) IBOutlet UILabel *typeLabel;

@property (weak, nonatomic) IBOutlet UIButton *todoBtn;
@property (weak, nonatomic) IBOutlet UIButton *activityBtn;

@end

@implementation ZClubCell

- (void)zSetupCell
{
    [super zSetupCell];
    [self.contentView setBackgroundColor:NAVBAR_BG_COLOR];
    [self setBackgroundColor:NAVBAR_BG_COLOR];
    
    // ========== 阴影与圆角处理 ==========
    [self zShadowAndCornerDeal:12];
    [self.logoImgView zCornerDeal:22];
    [self.typeLabel zLeftCornerDeal:8];
    self.memberBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -6, 0, 0);
}

- (void)updateContent
{
    // Todo: Logo下载更新处理, 组织类型
    self.titleLabel.text = self.model.clubName;
    [self.memberBtn setTitle:[NSString stringWithFormat:@"%zd", self.model.memberCount] forState:UIControlStateNormal];
    [self.todoBtn setTitle:[NSString stringWithFormat:@"待办: %zd", self.model.todoCount] forState:UIControlStateNormal];
    [self.activityBtn setTitle:[NSString stringWithFormat:@"活动: %zd", self.model.activityCount] forState:UIControlStateNormal];
    
    if (self.model.avatarUrl != nil) {
        [self.logoImgView sd_setImageWithURL:[NSURL URLWithString:self.model.avatarUrl]];
    }
}

#pragma mark - Control Action

- (IBAction)groupChatAction:(id)sender
{
    if (self.didSelectedGroupChat) {
        self.didSelectedGroupChat(self.model);
    }
}

- (IBAction)todoAction:(id)sender
{
    if (self.didSelectedTodo) {
        self.didSelectedTodo(self.model);
    }
}

- (IBAction)activityAction:(id)sender
{
    if (self.didSelectedActivity) {
        self.didSelectedActivity(self.model);
    }
}

#pragma mark - Getter & Setter

- (void)setModel:(ZClubModel *)model
{
    _model = model;
    
    [self updateContent];
}

@end
